#include "../Views/VGate.h"

VGate::VGate()
{
    this->setWindowTitle("Caracteristiques de la porte");
    this->title = new QLabel("<center><h3>Nouvelle Porte</h3></center>");
    this->validate_button = new QPushButton("Valider");
    this->cancel_button = new QPushButton("Annuler");
    this->ip_line = new QLineEdit();
    this->port_line = new QLineEdit();
    this->form_layout = new QFormLayout();
    this->form_layout->addRow("IP", this->ip_line);
    this->form_layout->addRow("Port", this->port_line);
    this->h_layout = new QHBoxLayout();
    this->h_layout->addWidget(this->validate_button);
    this->h_layout->addWidget(this->cancel_button);
    this->v_layout = new QVBoxLayout();
    this->v_layout->addLayout(this->form_layout);
    this->v_layout->addLayout(this->h_layout);
    this->setLayout(this->v_layout);

    QObject::connect(this->validate_button, SIGNAL(clicked()), this, SLOT(validate()));
    QObject::connect(this->ip_line, SIGNAL(returnPressed()), this, SLOT(validate()));
    QObject::connect(this->port_line, SIGNAL(returnPressed()), this, SLOT(validate()));
    QObject::connect(this->cancel_button, SIGNAL(clicked()), this, SLOT(cancel()));
}

VGate::~VGate()
{
    delete this->title;
    delete this->validate_button;
    delete this->cancel_button;
    delete this->ip_line;
    delete this->port_line;
    delete this->form_layout;
    delete this->v_layout;
}

// Essayer de créer la porte
void VGate::validate()
{
    this->ip = this->port_line->text();
    this->port = (quint16)(this->ip.toInt());
    this->ip = this->ip_line->text();
    this->close();
}

// Annuler la création de la porte
void VGate::cancel()
{
    this->ip = "";
    this->port = (quint16)(0);
    this->close();
}
